package ynu.edu.Controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import ynu.edu.Entity.PhoneNumber;
import ynu.edu.Entity.User;

@RestController
@RequestMapping("/number")
public class PhoneController {

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/getNumberByUserId/{userId}")
    public PhoneNumber getNumberByUserId(@PathVariable("userId") Integer userId){

        PhoneNumber phoneNumber = new PhoneNumber();
        phoneNumber.setPhoneNum("7777-123456789");
        User u =restTemplate.getForObject("http://localhost:11111/user/getUserById/"+userId.toString(), User.class);
        phoneNumber.setUser(u);
        return phoneNumber;
    }
}
